<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/icons-extra.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">	
			<a class="mui-icon mui-icon-back mui-action-back mui-pull-left"></a>
			<h1 class="mui-title ">downloader</h1>
			<a class="mui-icon-extra mui-icon-extra-topic mui-pull-right" style="margin-top: 10px;"
				 onclick="openWindow('docdownloader','../doc/downloader.html?v=20190621')"></a>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded">
				<div class="mui-row">
					Downloader模块管理网络文件下载任务，用于从服务器下载各种文件，并支持跨域访问操作。通过plus.downloader获取下载管理对象。Downloader下载使用HTTP的GET/POST方式请求下载文件，符合标准HTTP/HTTPS传输协议。
				</div>
				<div class="mui-button-row">
					<button type="button" class="mui-btn mui-btn-success mui-btn-block"  onclick="createDownloadTask()">创建下载任务</button>
					<button type="button" class="mui-btn mui-btn-primary mui-btn-block" onclick="startDownloadTask()">启动下载任务</button>
					<button type="button" class="mui-btn mui-btn-primary mui-btn-block" onclick="pauseDownloadTask()">暂停下载任务</button>
					<button type="button" class="mui-btn mui-btn-primary mui-btn-block" onclick="resumeDownloadTask()">恢复下载任务</button>
					<button type="button" class="mui-btn mui-btn-primary mui-btn-block" onclick="cancelDownloadTask()">取消下载任务</button>
					<button type="button" class="mui-btn mui-btn-primary mui-btn-block" onclick="clearDownloadTask()">清除所有任务</button>
				</div>
				<ul id="history" class="dlist" style="text-align:left;">
					<li id="nohistory" class="ditem" onclick="onempty()">无历史记录	</li>
				</ul>
				
				<div class="mui-row" id="divInfo"></div>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/app.js" ></script>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript">
			mui.init();
			function outSet(message){
				document.getElementById("divInfo").innerText = message;
			}
			
			function outLine(message){
				var text = document.getElementById("divInfo").innerText;
				document.getElementById("divInfo").innerText = text + "\n" + message;
			}
			
			var dtask=null;
			function createDownloadTask(){
				if ( dtask ) {
					outLine( "下载任务已创建！" );
					return;
				}
			    var url = "http://snip.qq.com/resources/Snip_V2.0_5771.dmg";
			    var options = {method:"GET"};
				dtask = plus.downloader.createDownload( url, options );
			    dtask.addEventListener( "statechanged", function(task,status){
			    	if(!dtask){return;}
			    	switch(task.state) {
			    		case 1: // 开始
			    			outLine( "开始下载..." );
			    		break;
			    		case 2: // 已连接到服务器
			    			outLine( "链接到服务器..." );
			    		break;
			    		case 3:	// 已接收到数据
			    			outSet( "下载数据更新:" );
			    			outLine( task.downloadedSize+"/"+task.totalSize );
			    		break;
			    		case 4:	// 下载完成
			    			outSet( "下载完成！" );
			    			outLine( task.totalSize );
			    		break;
			    	}
			    } );
			    outSet( "创建下载任务成功！" );
			}
			function startDownloadTask(){
				if ( !dtask ) {
					outSet( "请先创建下载任务！" );
					return;
				}
				dtask.start();
			}
			// 暂停下载任务
			function pauseDownloadTask(){
			    dtask.pause();
			    outSet( "暂停下载！" );
			}
			// 恢复下载任务
			function resumeDownloadTask(){
			    dtask.resume();
			    outSet( "恢复下载！" );
			}
			function cancelDownloadTask(){
				dtask.abort();
				dtask = null;
				outSet( "取消下载任务！" );
			}
			function clearDownloadTask(){
				
			}
			function startAll(){
				plus.downloader.startAll();
			}
		</script>
	</body>

</html>